package it.storm.solution;

import java.util.ArrayList;
import java.util.List;

/**
 * 1732. 找到最高海拔
 * https://leetcode-cn.com/problems/find-the-highest-altitude/
 */
public class Solutions_1732 {
    public static void main(String[] args) {
        int[] nums1 = {-5, 1, 5, 0, -7};  // output: 1
        int[] nums2 = {-4, -3, -2, -1, 4, 3, 2};  // output: 0

        List<int[]> inputs = new ArrayList<>();
        inputs.add(nums1);
        inputs.add(nums2);

        for (int[] input : inputs) {
            int result = largestAltitude(input);
            System.out.println(result);
        }
    }

    /**
     * gain 中的元素，记录的是两个数之间的差值
     */
    public static int largestAltitude(int[] gain) {
        int res = 0;
        int n = 0;

        for (int num : gain) {
            n += num;
            res = Math.max(res, n);
        }
        return res;
    }
}
